 <extend name="public:base"/>

<block name="left"></block>
<block name="menu"></block>

<block name="css">
    <link rel="stylesheet" href="__CSS__/sign.css"/>
</block>

<block name="main">

    <div class="regWrapper">
        <div class="regTitle cl">
            <h2 class="fl f18">找回密码</h2>
            <span class="fl a999">
			<a href="{:url('user/passport/login')}" class="aBlue">返回登录</a>
		</span>
        </div>
        <div class="registerStep cl forgetPwd" style="margin-top: 10px;">
            <form action="{:url('user/passport/find')}" method="POST" id="setPasswordForm">
                {:token()}
                <div class="inputWrapper">
                    <div class="inputBox">
                        <input style="border-color: #dedede  " type="text" name="phone" maxlength="11" value=""
                               class="input" id="mobile" autocomplete="off" placeholder="请输入手机号码"/>
                        <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                    </div>
                    <div class="inputBox minInput">
                        <div style="border: 1px #dedede solid;width:347px;height: 38px;border-radius: 3px">
                            <input style="border: 0;height:38px;line-height: 38px;position: absolute" type="text"
                                   name="verify" value="" maxlength="4" class="input verifyInput" autocomplete="off"
                                   id="imgCode" placeholder="输入右图中的字符，不区分大小写"/>
                            <img src="{:captcha_src(2)}" class="verifyImg reloadVerify"
                                 style="left: 250px;right: 0;height: 38px;"/>
                        </div>

                        <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                    </div>
                    <div class="inputBox minInput">
                        <div style="border: 1px #dedede solid;width:347px;height: 38px;border-radius: 3px">
                            <input style="border: 0;height:38px;line-height: 38px;position: absolute" type="text"
                                   name="scode" maxlength="6" value="" class="input" id="phoneCode" autocomplete="off"
                                   placeholder="请输入短信验证码"/>
                            <input type="button" class="btn_b" id="sendMsgBtn" value="获取短信验证码"
                                   style="left: 233px;right: 0;height: 38px;line-height: 38px;top:1px;"/>
                        </div>
                        <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                    </div>
                    <div class="inputBox pwd none">
                        <input type="password" name="password1" maxlength="16" value="" class="input" id="pwd1"
                               autocomplete="off" placeholder="请输入8-16位字母和数字组合新密码"/>
                        <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                    </div>
                    <div class="inputBox pwd none">
                        <input type="password" name="password2" maxlength="16" value="" class="input" id="pwd2"
                               autocomplete="off" placeholder="请再次输入8-16位字母和数字组合新密码"/>
                        <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                    </div>
                </div>
                <div class="submitLine mc">
                    <p class="mb20 mt10">
                        <input type="submit" value="立即设置" class="btn_b" id="inputSubmit"/>
                    </p>
                </div>
            </form>
        </div>
    </div>

</block>

<block name="footer">
    <include file="../template/default/index/public/min_footer.html"/>
</block>

<block name="js">

    <script type="text/javascript" src="__JS__/sign.js?v={:config('app_ver')}"></script>
    <script type="text/javascript">

        $(function () {

            $("#mobile").blur(function () {
                checkPhone()
            });
            $("#imgCode").blur(function () {
                checkImgCode()
            });
            $("#phoneCode").blur(function () {
                checkPhoneCode()
            });
            $("#pwd1").blur(function () {
                setPassword1()
            });
            $("#pwd2").blur(function () {
                setPassword2()
            });

            // 发送短信
            $('#sendMsgBtn').click(function () {
                var phone = $('#mobile').val();
                var vCode = $("#imgCode").val();
                checkPhone();
                checkImgCode();
                if (!checkImgCode() || !checkPhone()) {
                    return false;
                }
                $.ajax({
                    url: "{:url('user/passport/find_sms')}",
                    type: "post",
                    dataType: "json",
                    data: {phone: phone, verify: vCode},
                    success: function (data) {
                        if (data.code == 1) {
                            settTime();
                            $(".inputBox.pwd").show();
                            layer.alert(data.msg, {icon: 1});
                        } else {
                            if (data.msg) {
                                layer.alert(data.msg, {icon: 2});
                                $("#imgCode").val('');
                                $('.reloadVerify').click();
                                return false;
                            }
                            checkErrorType(data);
                            return false;
                        }
                    }
                });
                return false;
            });

            //提交表单
            $("#setPasswordForm").submit(function () {
                var self = $(this);
                checkPhone();
                checkImgCode();
                checkPhoneCode();
                if (checkPhone() && checkImgCode() && checkPhoneCode()) {
                    setPassword1();
                    setPassword2();
                }
                if (!(checkPhone() && checkImgCode() && checkPhoneCode() && setPassword1() && setPassword2())) {
                    return false;
                }
                $.post(self.attr("action"), self.serialize(), success, "json");
                return false;

                function success(data) {
                    if (data.code === 1) {
                        layer.alert(data.msg, {icon: 1}, function (index) {
                            if (data.data || data.url) {
                                var refer = data.data || data.url;
                                layer.close(index);
                                window.location.href = refer;
                                setTimeout(function () {
                                    window.location.href = refer;
                                }, 2000);
                            } else {
                                window.location.reload();
                            }
                        });

                    } else {
                        if (data.msg !== '') {
                            layer.alert(data.msg, {icon: 2});
                        } else {
                            checkErrorType(data);
                        }
                    }
                }

            });
        })
    </script>
</block>

